clear all

*Set working folders. Please change the global variable "user" to the folder with the replication package
global user "C:\Users\weilingliu1990\Dropbox\Insurance Project\LTCI Replication Package"
global data "$user\Data"
global images "$user\Images"
global drafttab "$user\Tables"

set maxvar  32767
*ssc install estout						//will need to install if you don't already have it

********** TABLE 10 ********
use "$data\competition_data", clear
//TABLE 10A
gen prem=(earned_prem)/ inforce_ct
eststo: reghdfe prem L.apply Lc.pct_approved i.year i.state_num i.co_code,  absorb(id) vce(cluster double_cluster)
 quietly summ prem if e(sample)
estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "No"
eststo: reghdfe prem L(1/2).apply L(1/2)c.pct_approved i.year i.state_num i.co_code,  absorb(id) vce(cluster double_cluster)
 quietly summ prem if e(sample)
estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "No"
eststo: reghdfe prem L(1/3).apply L(1/3)c.pct_approved i.year i.state_num i.co_code,  absorb(id) vce(cluster double_cluster)
 quietly summ prem if e(sample)
estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "No"
eststo: reghdfe prem L.apply Lc.pct_approved i.year i.state_num i.co_code,  absorb(id double_cluster) vce(cluster double_cluster)
 quietly summ prem if e(sample)
estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "Yes"
eststo: reghdfe prem L(1/2).apply L(1/2)c.pct_approved i.year i.state_num i.co_code,  absorb(id double_cluster) vce(cluster double_cluster)
 quietly summ prem if e(sample)
estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "Yes"
eststo: reghdfe prem L(1/3).apply L(1/3)c.pct_approved i.year i.state_num i.co_code,  absorb(id double_cluster) vce(cluster double_cluster)
 quietly summ prem if e(sample)
estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "Yes"
esttab using "$drafttab\Table_10A.tex" , b(%4.2f) se(%4.2f) star(* 0.10 ** 0.05 *** 0.01) ///
scalars("ysum Mean Dependent Variable" "fe Company x State FE" "cofe State x Year FE" "app Control for Whether Applied" "N Number of Observations" "r2 R-squared") ///
sfmt(%4.2f %4.2f %4.2f %7.0fc %4.2f %4.3f) noobs lines ///
label keep( *pct*) nogaps numbers nobaselevels f ///
nomtitles replace
eststo clear


//TABLE 10B
eststo: reghdfe cash L.apply Lc.pct_approved i.year i.state_num i.co_code,  absorb(id) vce(cluster double_cluster)
 quietly summ cash if e(sample)
  estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "No"
eststo: reghdfe cash L(1/2).apply L(1/2)c.pct_approved i.year i.state_num i.co_code,  absorb(id) vce(cluster double_cluster)
 quietly summ cash if e(sample)
  estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "No"
eststo: reghdfe cash L(1/3).apply L(1/3)c.pct_approved i.year i.state_num i.co_code,  absorb(id) vce(cluster double_cluster)
 quietly summ cash if e(sample)
  estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "No"
eststo: reghdfe cash L.apply Lc.pct_approved i.year i.state_num i.co_code,  absorb(id double_cluster) vce(cluster double_cluster)
 quietly summ cash if e(sample)
  estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "Yes"
eststo: reghdfe cash L(1/2).apply L(1/2)c.pct_approved i.year i.state_num i.co_code,  absorb(id double_cluster) vce(cluster double_cluster)
 quietly summ cash if e(sample)
  estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "Yes"
eststo: reghdfe cash L(1/3).apply L(1/3)c.pct_approved i.year i.state_num i.co_code,  absorb(id double_cluster) vce(cluster double_cluster)
 quietly summ cash if e(sample)
  estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "Yes"
esttab using "$drafttab\Table_10B.tex" , b(%4.2f) se(%4.2f) star(* 0.10 ** 0.05 *** 0.01) ///
scalars("ysum Mean Dependent Variable" "fe Company x State FE" "cofe State x Year FE" "app Control for Whether Applied" "N Number of Observations" "r2 R-squared") ///
sfmt(%4.2f %4.2f %4.2f %7.0fc %4.2f %4.3f) noobs lines ///
label keep( *pct*) nogaps numbers nobaselevels f ///
nomtitles replace
eststo clear

//TABLE 10C
eststo: reghdfe inforce_ct L.apply Lc.pct_approved i.year i.state_num i.co_code,  absorb(id) vce(cluster double_cluster)
 quietly summ inforce_ct if e(sample)
 estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "No"
eststo: reghdfe inforce_ct L(1/2).apply L(1/2)c.pct_approved i.year i.state_num i.co_code,  absorb(id) vce(cluster double_cluster)
 quietly summ inforce_ct if e(sample)
 estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "No"
eststo: reghdfe inforce_ct L(1/3).apply L(1/3)c.pct_approved i.year i.state_num i.co_code,  absorb(id) vce(cluster double_cluster)
 quietly summ inforce_ct if e(sample)
 estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "No"
eststo: reghdfe inforce_ct L.apply Lc.pct_approved i.year i.state_num i.co_code,  absorb(id double_cluster) vce(cluster double_cluster)
 quietly summ inforce_ct if e(sample)
 estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "Yes"
eststo: reghdfe inforce_ct L(1/2).apply L(1/2)c.pct_approved i.year i.state_num i.co_code,  absorb(id double_cluster) vce(cluster double_cluster)
 quietly summ inforce_ct if e(sample)
 estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "Yes"
eststo: reghdfe inforce_ct L(1/3).apply L(1/3)c.pct_approved i.year i.state_num i.co_code,  absorb(id double_cluster) vce(cluster double_cluster)
 quietly summ inforce_ct if e(sample)
estadd scalar ysum = r(mean)
estadd local fe "Yes"
estadd local app "Yes"
estadd local cofe "Yes"
esttab using "$drafttab\Table_10C.tex" , b(%4.2f) se(%4.2f) star(* 0.10 ** 0.05 *** 0.01) ///
sfmt(%4.2f %4.2f %4.2f %7.0fc %4.2f %4.3f) noobs lines ///
scalars("ysum Mean Dependent Variable" "fe Company x State FE" "cofe State x Year FE" "app Control for Whether Applied" "N Number of Observations" "r2 R-squared") ///
label keep( *pct*) nogaps numbers nobaselevels f ///
nomtitles replace
eststo clear
